package com.rran.study.designpattern.behavioral.observer;

import com.rran.study.designpattern.behavioral.observer.listener.spring.RranListener;
import com.rran.study.designpattern.behavioral.observer.listener.spring.RranListener2;
import com.rran.study.designpattern.behavioral.observer.service.RranEventService;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * 使用spring的监听器实现观察者模式
 * 发布一个Rran事件，RranListener和RranListener2两个监听器都能监听到RranEventService发送的事件
 * 支持异步
 */
@Configuration
//@EnableAsync
@Import({RranEventService.class,RranListener.class,RranListener2.class})
public class SpringObserverApplication {

    public static void main(String[] args) throws Exception {

        //非web方式启动
        ConfigurableApplicationContext context = new SpringApplicationBuilder(SpringObserverApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);

        RranEventService rranEventService = context.getBean(RranEventService.class);
        rranEventService.publishRran();


        context.close();
    }
}
